﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CourierManager
{
    public static class ValidatorPhone
    {
        public static string ValidatePhoneNumberFromString(string individualNumber)
        {
            string splittedIndividualNumber = RemoveSymbolsInPhoneNumber(individualNumber);
            if (splittedIndividualNumber.Length < 9 || splittedIndividualNumber.Length > 11)
            {
                throw new InvalidPhoneNumberException("Invalid phone number!", splittedIndividualNumber);
            }
            return splittedIndividualNumber;
        }

        private static string RemoveSymbolsInPhoneNumber(string phoneNumber)
        {
            //string[] arr = phoneNumber.Split(new string[] {" ","-","/" }, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder builder = new StringBuilder();
            //builder.Append(phoneNumber);
            for (int i = 0; i < phoneNumber.Length; i++)
            {
                if (phoneNumber[i] != '/' && phoneNumber[i] != '-' && phoneNumber[i] != ' ')
                {
                    builder.Append(phoneNumber[i]); 
                }
            }
            return builder.ToString();
        }
        
    }
}
